import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import p002 from './p002';
import p003 from './p003';
import p005 from './p005';

export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// todo
	// 点击 我发出的 触发
	// 表格
	const up = fd.data.node.querySelector<HTMLDivElement>('[data-id="myup"]');
	set_node_cls(up, 'display-n', false);
	const up1 = fd.data.node.querySelector<HTMLDivElement>('[data-id="myin"]');
	set_node_cls(up1, 'display-n', true);
	// 头部
	const up2 = fd.data.node.querySelector<HTMLDivElement>('[data-id="myshou"]');
	const up3 = fd.data.node.querySelector<HTMLDivElement>('[data-id="myfa"]');
	set_node_cls(up2, 'bg-themef', false);
	set_node_cls(up3, 'bg-themef', true);
	const up4 = fd.data.node.querySelector<HTMLDivElement>('[data-id="mysdao"]');
	const up5 = fd.data.node.querySelector<HTMLDivElement>('[data-id="myfchu"]');
	set_node_cls(up5, 'display-n', false);
	set_node_cls(up5, 'flex-js-c', true);
	set_node_cls(up4, 'flex-js-c', false);
	const up6 = fd.data.node.querySelector<HTMLDivElement>('[data-id="p003"]');
	const up7 = fd.data.node.querySelector<HTMLDivElement>('[data-id="p005"]');
	set_node_cls(up6, 'display-n', true);
	set_node_cls(up7, 'display-n', false);
	// 系统参数staff-no
	const inform_title1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="inform_title1"]');
	// 时间
	const receive_time1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="receive_time1"]');
	const receive_time_end1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="receive_time_end1"]');
	inform_title1.value = "";
	receive_time1.value = "";
	receive_time_end1.value = "";
	const a1 = get('staff_no');
	set(fd,'staff_no1',a1);
	const res1 = await nodejs<{
		res: Array<{inform_no: string, inform_title: string, inform_content: string,
			notification_time: number, pub_user_no: string, pub_user_name: string}>; res3: Array<{
			inform_no: string, inform_title: string, inform_content: string,
			notification_time: number, pub_user_no: string, pub_user_name: string
		}>; res1: number
	}>('notification-notice/zj-000001/s005',
		{
			filter: {
				pn: 1,
				a: a1
			}
		});
	 console.log(res1.res.length);
	const arr1 = Array();
	const num = res1.res.length;
	const num2 = res1.res1[0].inform_title;
	console.log('num2',num2);
	for (let i = 0; i < num; i++) {
		arr1.push(res1.res[i].inform_no);
	}
	// 格式化日期
	const newres1 = res1.res.map((n) => {
		return { ...n, receive_time: format(n.notification_time, 2) };
	});
	// console.log('数组', arr1);
	const arr3 = Array();
	for (let i = 0; i < arr1.length; i++) {
		const res3 = await nodejs<{ dt: Array<{ inform_no: string, pub_user_no: string, pub_user_name: string }> }>('notification-notice/zj-000001/s006',
			{
				filter: {
					arr: arr1[i]
				}
			});
		arr3.push(res3.dt);
	}
	// console.log(arr3);
	const arr5 = Array();
	for (let i = 0; i < arr3.length; i++) {
		let strName = "";
		for (let j = 0; j < arr3[i].length; j++) {
			if (arr3[i].length === 0) {
				strName = "";
			}
			if (arr3[i].length === 1) {
				strName += arr3[i][j].pub_user_name;
			}
			if (arr3[i].length === 2) {
				if (j === 1) {
					strName += arr3[i][j].pub_user_name;
				}
				if (j < 1) {
					strName += arr3[i][j].pub_user_name + ",";
				}
			}
			if (arr3[i].length === 3) {
				if (j === 2) {
					strName += arr3[i][j].pub_user_name;
				}
				if (j < 2) {
					strName += arr3[i][j].pub_user_name + ",";
				}
			}
			if (arr3[i].length > 3) {
				if (j < 2) {
					strName += arr3[i][j].pub_user_name + ",";
				}
				if (j === 2) {
					strName += arr3[i][j].pub_user_name + "...";
				}
			}
		}
		arr5.push(strName);

	}
	let a = 0;
	const newarr = newres1.map((n) => {
		n.pub_user_name = arr5[a];
		a++;
		return n;
	});
	const dtData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const dtNoData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	const dtPn = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	if (newres1.length > 0) {
		render(fd, newarr, p002, "p002", "inner");
		dtNoData.style.display = 'none';
		dtData.style.display = 'block';

		if (num >= 20) {
			render(fd, num2, p005, 'p005', "inner");
			dtPn.style.display = 'block';
		}
	} else {
		render(fd, "", p003, 'p003', 'inner');
		dtNoData.style.display = 'none';
		dtData.style.display = 'block';
		dtPn.style.display = 'none';
	}


}
